package com.xinli.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xinli.business.domain.FtMember;
import com.xinli.business.service.IFtMemberService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinli.common.annotation.Log;
import com.xinli.common.core.controller.BaseController;
import com.xinli.common.core.domain.AjaxResult;
import com.xinli.common.enums.BusinessType;
import com.xinli.common.utils.poi.ExcelUtil;
import com.xinli.common.core.page.TableDataInfo;

/**
 * 学员信息Controller
 *
 * @author ruoyi
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/business/member")
public class FtMemberController extends BaseController
{
    @Autowired
    private IFtMemberService ftMemberService;

    /**
     * 查询学员信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(FtMember ftMember)
    {
        startPage();
        List<FtMember> list = ftMemberService.selectFtMemberList(ftMember);
        return getDataTable(list);
    }

    /**
     * 导出学员信息列表
     */
    @Log(title = "学员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FtMember ftMember)
    {
        List<FtMember> list = ftMemberService.selectFtMemberList(ftMember);
        ExcelUtil<FtMember> util = new ExcelUtil<FtMember>(FtMember.class);
        util.exportExcel(response, list, "学员信息数据");
    }

    /**
     * 获取学员信息详细信息
     */
    @GetMapping(value = "/{memberId}")
    public AjaxResult getInfo(@PathVariable("memberId") Long memberId)
    {
        return AjaxResult.success(ftMemberService.selectFtMemberByMemberId(memberId));
    }

    /**
     * 新增学员信息
     */
    @Log(title = "学员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FtMember ftMember)
    {
        return toAjax(ftMemberService.save(ftMember));
    }

    /**
     * 修改学员信息
     */
    @Log(title = "学员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FtMember ftMember)
    {
        return toAjax(ftMemberService.updateById(ftMember));
    }

    /**
     * 删除学员信息
     */
    @Log(title = "学员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{memberIds}")
    public AjaxResult remove(@PathVariable Long[] memberIds)
    {
        return toAjax(ftMemberService.removeByIds(Arrays.asList(memberIds)));
    }
}
